<!--
จำเป็นต้องมีสำหรับ หน้า print
div => "head" ถูกแสดงด้านบนทุกหน้า
thead => "tableHead" หัวตารางที่จะถูกแสดงทุกหน้า
2 => "" หัวตารางที่จะถูกแสดงทุกหน้า
tr => "row[no]" แถวในตาราง, class => "row"
td => class => "rowTd" ใช้หาความสูงแดวตารางใน IE
tr => "emptyRow" แถวว่างท้ายตาราง
4 => "foot" แสดงที่ส่วนท้ายทุกหน้า
-->
<div id="divFirstHeader"></div>  <div class="header">
    <div class="title"><?php echo $this->element('print/title'); ?></div>
    <div class="documentTitle">
        <div class="documentNote">RETURN NOTE</div>
        <table class="documentNo">
            <tr>
                <td><label>Return no.</label></td>
                <td><?php echo $this->data['DRH']['return_no']; ?></td>
            </tr>
        </table>
        <table>
            <tr>
                <td><label>Return date</label></td>
                <td><?php echo $this->data['DRH']['return_date']; ?></td>
                <td><label>Page</label></td>
                <td><span class="pageNo">1/1</span></td>
            </tr>
            <tr>
                <td width="120px"><label>Ref by Dispatch no.</label></td>
                <td colspan="3"><?php echo $this->data['Dispatch']['dispatch_no']; ?></td>
            </tr>
            <tr>
                <td><label>Return by</label></td>
                <td colspan="3"><?php echo $this->data['DRH']['return_by']; ?></td>
            </tr>
            <tr>
                <td><label>Warehouse</label></td>
                <td colspan="3"><?php echo $this->data['Warehouse']['name']; ?></td>
            </tr>
        </table>
    </div>
    <table class="wide clear">
        <tr>
            <td width="120px"><label>Customer no.</label></td>
            <td width="290px"><?php echo $this->data['Customer']['cust_no']; ?></td>
            <td width="125px"><label>Site no.</label></td>
            <td><?php echo $this->data['Site']['site_no']; ?></td>
        </tr>
        <tr>
            <td><label>Customer name</label></td>
            <td><?php echo $this->data['Customer']['name']; ?></td>
            <td><label>Site name</label></td>
            <td><?php echo $this->data['Site']['name']; ?></td>
        </tr>
    </table>
</div>

<div class="main">
    <table id="dataTable" class="dataTable" cellspacing="0" cellpadding="0" >
        <thead id="tableHead">
            <tr align="center">
                <th width="40px">Item<br>ลำดับ</th>
                <th width="120px">Part Number<br>รหัสสินค้า</th>
                <th>Description<br />รายการ</th>
                <th width="45px">Qty<br />จำนวน</th>
                <th width="45px">Unit<br />หน่วย</th>
                <th width="70px">Price/Unit<br>ราคา/หน่วย</th>
                <th width="70px">Amount<br>จำนวนเงิน</th>
                <th width="80px">Location<br />ตำแหน่ง</th>
            </tr>
        </thead>
        <tbody id="tableBody">
            <?php $i = 0; foreach($this->data['DR'] as $dr) : ?>
                <?php
                $pl_count = count($dr['ProductLocation']);
                for ($j = 0; $j < $pl_count; ++$j):
                ?>
            <tr id="row<?php echo $i; ?>" class="row">
                <td class="center rowTd"><?php echo $j == 0? ($i + 1): '&nbsp;'; ?></td>
                <td><?php echo $dr['Product']['part_no']; ?></td>
                <td><?php echo $dr['Product']['text']; ?></td>
                <td class="text-right"><?php echo $dr['ProductLocation'][$j]['return_qty']; ?></td>
                <td class="center"><?php echo $dr['Product']['Unit']['title']; ?></td>
                <td class="text-right"><?php echo number_format($dr['ProductLocation'][$j]['price'], 2); ?></td>
                <td class="text-right"><?php echo number_format($dr['ProductLocation'][$j]['price'] * $dr['ProductLocation'][$j]['return_qty'], 2); ?></td>
                <td>
                        <?php echo !empty($dr['ProductLocation'][$j]['Location']['name'])?
                        $dr['ProductLocation'][$j]['Location']['name']:
                        'N/A'; // แสดง Location ถ้ามีข้อมูลอยู่?>
                </td>
            </tr>
            <?php
                // ถ้ามีแถวที่มี serial no หรือ other information อยู่ (ถ้าไม่มี จะมี แถวว่างมา 1 แถว)
                $k = 0;
                foreach($dr['ProductLocation'][$j]['PS'] as $ps) :
                    if (!empty($ps['ProductSerial']['serial_no']) || !empty($ps['ProductSerial']['other_information'])) : ?>
                <tr class="product_serials_row">
                    <td>&nbsp;</td>
                    <td class="rowTd">
                        <span class="product_serial_no"><?php echo ++$k; ?>&nbsp;</span>
                        <span><?php echo !empty($ps['ProductSerial']['serial_no'])? $ps['ProductSerial']['serial_no']: 'N/A' ?></span>
                    </td>
                    <td>
                        <span><?php echo !empty($ps['ProductSerial']['other_information'])? $ps['ProductSerial']['other_information']: 'N/A' ?></span>
                    </td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                </tr>
                <?php endif; endforeach; ?>
                <?php endfor; ++$i; ?>
            <?php endforeach; ?>
            <?php for ($i = 0; $i < 30; ++$i) : ?>
            <tr class="emptyRow"> <!-- สร้างแถวเปล่าขึ้นมาเพื่อยืดขนาดตารางให้เต็มหน้า-->
                <td class="rowTd">&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
            </tr>
            <?php endfor; ?>
        </tbody>
    </table>
</div>

<div class="footer">
    <div class="remark">
        <label>Remark</label><br />
        <?php echo $this->data['DRH']['remark']; ?>
    </div>
    <div class="custSignature">
        <hr />
        <span>ITS Staff/Date</span>
    </div>
</div>
